/*
 * Created by SharpDevelop.
 * User: Oscar
 * Date: 04/10/2007
 * Time: 07:06 p.m.
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Web;
using System.Web.UI.WebControls;

namespace DemoPress.Web
{
    /// <summary>
    /// Description of LogonControl.
    /// </summary>
    public class LogonControl : WebControl
    {
        private string _welcomeText;
        private string _nameLabelText;
        private string _passLabelText;
        private TextBox _tbxName;
        private TextBox _tbxPass;
        private Button _button;

        public string NameValue
        {
            get { return _tbxName.Text; }
            set { _tbxName.Text = value; }
        }

        public string PassValue
        {
            get { return _tbxPass.Text; }
            set { _tbxPass.Text = value; }
        }

        public string PassLabelText
        {
            get { return _passLabelText; }
            set { _passLabelText = value; }
        }

        public string WelcomeText
        {
            get { return _welcomeText; }
            set { _welcomeText = value; }
        }

        public string NameLabelText
        {
            get { return _nameLabelText; }
            set { _nameLabelText = value; }
        }

        public string ButtonText
        {
            get { return _button.Text; }
            set { _button.Text = value; }
        }

        public LogonControl()
        {
            _tbxName = new TextBox();
            _tbxName.ID = ID + "NameText";
            this.Controls.Add(_tbxName);
            _tbxPass = new TextBox();
            _tbxPass.ID = ID + "PassText";
            this.Controls.Add(_tbxPass);
            _button = new Button();
            _button.Text = "Enter";
            this.Controls.Add(_button);
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            // renders main div tag
            RenderDiv(writer, ID);
            // renders container div
            RenderDiv(writer, ID + "Container");

            RenderDiv(writer, ID + "Welcome");
            RenderLabel(writer, WelcomeText);
            writer.WriteEndTag("div");

            RenderDiv(writer, ID + "NameLabel");
            RenderLabel(writer, NameLabelText);
            _tbxName.RenderControl(writer);
            writer.WriteEndTag("div");

            RenderDiv(writer, ID + "PassLabel");
            RenderLabel(writer, PassLabelText);
            _tbxPass.RenderControl(writer);
            writer.WriteEndTag("div");

            RenderDiv(writer, ID + "Button");
            _button.RenderControl(writer);
            writer.WriteEndTag("div");

            // closes container div
            writer.WriteEndTag("div");
            // closes main div tag
            writer.WriteEndTag("div");
        }

        private void RenderLabel(System.Web.UI.HtmlTextWriter writer, string text)
        {
            writer.WriteFullBeginTag("span");
            writer.Write(text);
            writer.WriteEndTag("span");
        }

        private static void RenderDiv(System.Web.UI.HtmlTextWriter writer, string idValue)
        {
            writer.WriteBeginTag("div");
            writer.WriteAttribute("id", idValue);
            writer.Write(System.Web.UI.HtmlTextWriter.TagRightChar);
            writer.WriteLine();
        }
    }
}
